package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.systemmenu.BusinessSystemIdData;
import com.jinmdz.fmis.api.admin.model.systemmenu.SystemMenuIdData;
import com.jinmdz.fmis.api.admin.model.systemmenu.SystemMenuLoadData;
import com.jinmdz.fmis.api.admin.model.systemmenu.SystemMenuSaveData;
import com.jinmdz.fmis.api.admin.service.SystemMenuService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import com.jinmdz.fmis.dao.admin.model.systemmenu.SystemMenuListItem;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 系统菜单信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-18 16:16
 */
@Api(description = "系统菜单信息相关接口")
@RestController()
@RequestMapping("/admin/system-menu")
public class SystemMenuController extends BaseController {

    @Resource
    private SystemMenuService systemMenuService;

    /**
     * 根据业务系统id加载表【business_system_menu】中保存的业务系统菜单数据
     *
     * @param data 系统主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 16:18
     */
    @ApiOperation(value = "根据业务系统id加载表【business_system_menu】中保存的业务系统菜单数据", notes = "根据业务系统id加载表【business_system_menu】中保存的业务系统菜单数据")
    @PostMapping("/load-system-menu-list-with-business-system-id")
    public BaseResult<ArrayList<SystemMenuListItem>> loadSystemMenuListWithBusinessSystemId(@RequestBody BusinessSystemIdData data) {
        return resultHandler(data, userItem -> systemMenuService.loadSystemMenuListWithBusinessSystemId(data));
    }

    /**
     * 根据业务系统菜单id加载表【business_system_menu】中保存的业务系统菜单数据
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-18 16:19
     */
    @ApiOperation(value = "根据业务系统菜单id加载表【business_system_menu】中保存的业务系统菜单数据", notes = "根据表【business_system_menu】中id加载业务系统菜单数据")
    @PostMapping("/load-system-menu-with-id")
    public BaseResult<SystemMenuLoadData> loadSystemMenuWithId(@RequestBody SystemMenuIdData data) {
        return resultHandler(data, userItem -> systemMenuService.loadSystemMenuWithId(data));
    }

    /**
     * 保存菜单信息到business_system_menu表中
     *
     * @param data 请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-18 16:19
     */
    @ApiOperation(value = "保存菜单信息到【business_system_menu】表中", notes = "保存菜单信息到【business_system_menu】表中")
    @PostMapping("/save-system-menu")
    public BaseResult saveSystemMenu(@RequestBody SystemMenuSaveData data) {
        return resultHandler(data, userItem -> systemMenuService.saveSystemMenu(userItem, data));
    }

    /**
     * 从business_system_menu表中删除指定id的菜单信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-18 16:21
     */
    @ApiOperation(value = "从business_system_menu表中删除指定id的菜单信息记录", notes = "从business_system_menu表中删除指定id的菜单信息")
    @PostMapping("/delete-system-menu-with-id")
    public BaseResult deleteSystemMenuWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> systemMenuService.deleteSystemMenuWithId(userItem, data));
    }
}
